package cn.com.tianpeidong.restaurantadmin.project.admin.dishes.entity;

import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

/**
 * @author tianpeidong
 * 菜品
 */
@Data
@Entity
public class Dishes implements Serializable {

    @Id
    @Min(value = 1L)
    private Long id;

    /**
     * 菜品名
     */
    @NotBlank(message = "菜品名称不能为空")
    @Size(max = 20, message = "菜品名称长度必须小于等于20")
    private String dishesName;

    /**
     * 菜品类型id
     */
    @NotNull(message = "菜品类型不能为空")
    @Min(value = 1L, message = "菜品类型非法")
    private Long dishesTypeId;

    private String typeName;

    /**
     * 菜品图片地址
     */
    @NotBlank(message = "菜品图片不能为空")
    @Pattern(regexp = "\\bhttps://static.tianpeidong.com.cn/restaurant/\\S*?(.jpg|.png|.jpeg)\\b", message = "图片地址非法")
    private String avatar;

    /**
     * 菜品评分
     */

    private BigDecimal score;

    /**
     * 菜品价格
     */
    @NotNull
    @Digits(message = "菜品价格非法", integer = 5, fraction = 2)
    @DecimalMax(value = "99999.99", message = "菜品价格非法")
    @DecimalMin(value = "0.00", message = "菜品价格非法", inclusive = false)
    private BigDecimal price;

    /**
     * 菜品描述
     */
    @NotBlank(message = "菜品描述不能为空")
    @Size(max = 200, message = "菜品描述的长度必须小于等于200")
    private String description;

    private Integer upperStatus;

    private Date createdTime;
    private Date updatedTime;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Dishes dishes = (Dishes) o;
        return id.equals(dishes.id) &&
                dishesTypeId.equals(dishes.dishesTypeId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, dishesTypeId);
    }
}
